Date.prototype.format = function (format) //author: meizz
{
    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
    (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format))
        format = format.replace(RegExp.$1,
      RegExp.$1.length == 1 ? o[k] :
        ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}
function formatTime(val) {
    try {
        if (val.indexOf('-') >= 0) {
            return val;
        }
        else {
            var d = new Date();
            var re = /-?\d+/;
            var m = re.exec(val);
            var d = new Date(parseInt(m[0]));
            return d.format("yyyy-MM-dd");
        }
    } catch (e) {
        return "";
    }
}

angular.module('mycenter.controller', [])
  .controller('mycenterCtrl',['$scope','$timeout' ,'$localstorage','$ionicPopup','mycenterService','$state','loginService',function($scope,$timeout,$localstorage,$ionicPopup,mycenterService,$state,loginService){


      $scope.centerinfo = {};
    $scope.params={}; 
    $scope.params=mycenterService.getParams();
    $scope.doRefresh = function () {
        $scope.params.Depart_Code = $localstorage.get("Depart_Code");
        $scope.params.User_ID = $localstorage.get("User_ID");
        $scope.params.Phone = $localstorage.get("Phone");
        $scope.params.top = 10;   

        mycenterService.get_centerInfo($scope.params).then(function (data) {
            //data.Start_Date = formatTime(data.Start_Date);
            //data.End_Date = formatTime(data.End_Date);
            data['Phone'] = $scope.params.Phone;
            $scope.centerinfo = data;
        }, function (error) {
            var alertPopup = $ionicPopup.alert({
                title: '获取在网导航失败！',
                template: "异常错误",
                okText: '确定', // String (默认: 'OK')。OK按钮的文字。
                okType: 'item-customer-bg-darkred', // String (默认: 'button-positive')。OK按钮的类型。
            });
        });
    };
    $scope.$on('$ionicView.enter', function (event, data) {
        if ($scope.centerinfo['Start_Date'] == null) {
            $scope.doRefresh();
        }
          console.log("进入个人中心主页");
    });

  }]);
